package com.yunfei.schedule;
import com.yunfei.entity.messageSendDtl.MessageSendDtlEntity;
import com.yunfei.mapper.aiiidb.DaoZhangQueRenMessageForLiCaiShiMapper;
import com.yunfei.mapper.aiiidb.MessageSendDtlMapper;
import com.yunfei.utils.ComponentFactory;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @Description: 预约金额不足提醒-理财师
* @Author: zhengyunfei
* @Date: 2019/3/21
* @time:11:03
*/
@Component
public class YuYueJinEBuZuMessageForLiCaiShiScheduledTask {
    private static final org.slf4j.Logger Logger = LoggerFactory.getLogger(YuYueJinEBuZuMessageForLiCaiShiScheduledTask.class);
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-DD HH:mm:ss");
    /**
     * 每隔5秒执行, 单位：ms。
     */
  /*  @Scheduled(fixedRate = 5000)
    public void testFixRate() {
        System.out.println("我每隔5秒冒泡一次：" + dateFormat.format(new Date()));
        Logger.info("打印当前时间: {}.", dateFormat.format(new Date()));
    }*/

   //@Scheduled(cron = "0 0 1 * * ?")   //每天凌晨1点执行
    @Scheduled(cron = "0 0 */1 * * ?")   //每1小时
   /*@Scheduled(fixedRate = 50000000)*/
    public void testMyBatis() {
        System.out.println("到账确认提醒-理财师，定时任务。。。。。。。。");
        try {
            DaoZhangQueRenMessageForLiCaiShiMapper daoZhangQueRenMessageForLiCaiShiMapper = ComponentFactory.getBean(DaoZhangQueRenMessageForLiCaiShiMapper.class);
            Map<String,Object> paramMap=new HashMap<>();
            //第一步：存入通知表
            daoZhangQueRenMessageForLiCaiShiMapper.add(paramMap);
            //获取刚刚存入的消息ID
            List<MessageSendDtlEntity> messageSendList= daoZhangQueRenMessageForLiCaiShiMapper.findAllList(paramMap);
            //更新通知状态
            for(int i=0;i<messageSendList.size();i++){
                MessageSendDtlEntity param=messageSendList.get(i);
                daoZhangQueRenMessageForLiCaiShiMapper.update(param);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {

        }
    }
}

